package com.erp.shop.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.erp.shop.domain.bo.ErpSellerStoreEmpowerExtendBo;
import com.erp.shop.domain.vo.ErpSellerStoreEmpowerExtendVo;
import com.erp.shop.mapper.ErpSellerStoreEmpowerExtendMapper;
import com.erp.shop.service.IErpSellerStoreEmpowerExtendService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.shop.api.domain.ErpSellerStoreEmpower;
import com.ruoyi.shop.api.domain.ErpSellerStoreEmpowerExtend;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 卖家店铺Ae授权信息
 *
 * @author erp
 * @date 2023-04-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/seller/sellerStoreEmpowerExtend")
public class ErpSellerStoreEmpowerExtendController extends BaseController {

	private final IErpSellerStoreEmpowerExtendService iErpSellerStoreEmpowerExtendService;
	private final ErpSellerStoreEmpowerExtendMapper erpSellerStoreEmpowerExtendMapper;

	/**
	 * 查询卖家店铺Ae授权信息列表
	 */
	@SaCheckPermission("seller:sellerStoreEmpowerExtend:list")
	@GetMapping("/list")
	public TableDataInfo<ErpSellerStoreEmpowerExtendVo> list(ErpSellerStoreEmpowerExtendBo bo, PageQuery pageQuery) {
		return iErpSellerStoreEmpowerExtendService.queryPageList(bo, pageQuery);
	}

	/**
	 * 导出卖家店铺Ae授权信息列表
	 */
	@SaCheckPermission("seller:sellerStoreEmpowerExtend:export")
	@Log(title = "卖家店铺Ae授权信息", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(ErpSellerStoreEmpowerExtendBo bo, HttpServletResponse response) {
		List<ErpSellerStoreEmpowerExtendVo> list = iErpSellerStoreEmpowerExtendService.queryList(bo);
//		ExcelUtil.exportExcel(list, "卖家店铺Ae授权信息", ErpSellerStoreEmpowerExtendVo.class, response);
	}

	/**
	 * 获取卖家店铺Ae授权信息详细信息
	 *
	 * @param id 主键
	 */
	@SaCheckPermission("seller:sellerStoreEmpowerExtend:query")
	@GetMapping("/{id}")
	public R<ErpSellerStoreEmpowerExtendVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
		return R.ok(iErpSellerStoreEmpowerExtendService.queryById(id));
	}

	/**
	 * 新增卖家店铺Ae授权信息
	 */
	@SaCheckPermission("seller:sellerStoreEmpowerExtend:add")
	@Log(title = "卖家店铺Ae授权信息", businessType = BusinessType.INSERT)
	@RepeatSubmit()
	@PostMapping()
	public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpSellerStoreEmpowerExtendBo bo) {
		return toAjax(iErpSellerStoreEmpowerExtendService.insertByBo(bo));
	}

	/**
	 * 修改卖家店铺Ae授权信息
	 */
	@SaCheckPermission("seller:sellerStoreEmpowerExtend:edit")
	@Log(title = "卖家店铺Ae授权信息", businessType = BusinessType.UPDATE)
	@RepeatSubmit()
	@PutMapping()
	public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpSellerStoreEmpowerExtendBo bo) {
		return toAjax(iErpSellerStoreEmpowerExtendService.updateByBo(bo));
	}

	/**
	 * 删除卖家店铺Ae授权信息
	 *
	 * @param ids 主键串
	 */
	@SaCheckPermission("seller:sellerStoreEmpowerExtend:remove")
	@Log(title = "卖家店铺Ae授权信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
		return toAjax(iErpSellerStoreEmpowerExtendService.deleteWithValidByIds(Arrays.asList(ids), true));
	}

	/**
	 * 是否是人民币店铺
	 * 
	 * @return
	 */
	@GetMapping("/isRmb")
	public R<Object> isRmb(Long sellerId) {

		ErpSellerStoreEmpowerExtend erpSellerStoreEmpowerExtend = erpSellerStoreEmpowerExtendMapper
				.selectOne(new LambdaQueryWrapper<ErpSellerStoreEmpowerExtend>()
						.eq(ErpSellerStoreEmpowerExtend::getSellerId, sellerId)
						.eq(ErpSellerStoreEmpowerExtend::getType, 1));
		if (erpSellerStoreEmpowerExtend == null) {
			return R.fail();
		} else {
			String quotationCurrency = erpSellerStoreEmpowerExtend.getQuotationCurrency();
			if (quotationCurrency.equals("CNY"))
				return R.ok(true);
			else
				return R.ok(false);
		}
	}

	@PostMapping("/getSellerStoreExtendInfo")
	public R<Object> getSellerStoreExtendInfo(@RequestBody ErpSellerStoreEmpowerExtend erpSellerStoreEmpowerExtend) {
				return iErpSellerStoreEmpowerExtendService.getSellerStoreExtendInfo(erpSellerStoreEmpowerExtend);
	}

	@PostMapping("/getSellerStoreExtendInfoByStoreId/{storeId}")
	public R<Object> getSellerStoreExtendInfoByStoreId(@PathVariable("storeId") String storeId) {
				return iErpSellerStoreEmpowerExtendService.getSellerStoreExtendInfoByStoreId(storeId);
	}


}
